Spring-Data-JPA @Query注解 Sort排序 - 盲目的拾荒者的博客 - CSDN博客

创建时间:2019/1/3 20:11
来源:https://blog.csdn.net/niugang0920/article/details/79412586


  1. /**
  2. 2
    * 单条件排序
  3. 3
    */
  4. 4
    public List<User> findListSortSingleCondition(){
  5. 5
    //id升序查询
  6. 6
    Sort sort = new Sort(Sort.Direction.ASC,"id");
  7. 7
    return userDao.findUserLikeBySort(sort);
  8. 8
    }
  9. 9
    /**
  10. 10
    * 多条件排序
  11. 11
    */
  12. 12
    public List<User> findListSortMultiCondition(){
  13. 13
    List<Order> orders=new ArrayList<Order>();
  14. 14
    Order orderId = new Sort.Order(Sort.Direction.DESC,"id");
  15. 15
    Order orderAge = new Sort.Order(Sort.Direction.DESC,"age");
  16. 16
    orders.add(orderId);
  17. 17
    orders.add(orderAge);
  18. 18
    Sort sort = new Sort(orders);
  19. 19
    return userDao.findUserLikeBySort(sort);
  20. 20
    }